import os
import shutil
from pathlib import Path


def delete_exe_files():
    # 获取当前脚本所在目录
    current_dir = Path(__file__).parent
    # 获取当前文件夹的上一级主文件夹
    parent_dir = (current_dir.parent).parent
    # 构建C++文件夹路径
    cpp_dir = parent_dir / "C++"

    # 检查C++文件夹是否存在
    if not cpp_dir.exists():
        print(f"C++文件夹不存在: {cpp_dir}")
        return

    # 遍历C++文件夹下的所有文件夹
    for root, dirs, files in os.walk(cpp_dir):
        for file in files:
            if file.endswith(".exe"):
                file_path = os.path.join(root, file)
                try:
                    # 删除文件
                    os.remove(file_path)
                    print(f"已删除: {file_path}")
                except Exception as e:
                    print(f"删除文件 {file_path} 时出错: {e}")


if __name__ == "__main__":
    delete_exe_files()